﻿package mortal.game.scene3D.player.item
{
    import Message.DB.Tables.*;
    import Message.Game.*;
    import Message.Public.*;
    import baseEngine.modifiers.*;
    import extend.language.*;
    import flash.events.*;
    import frEngine.*;
    import frEngine.effectEditTool.temple.*;
    import frEngine.event.*;
    import frEngine.pools.*;
    import mortal.component.gconst.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.map3D.sceneInfo.*;
    import mortal.game.scene3D.model.data.*;
    import mortal.game.scene3D.model.player.*;
    import mortal.game.scene3D.model.pools.*;
    import mortal.game.scene3D.player.entity.*;
    import mortal.game.scene3D.player.head.*;
    import mortal.game.scene3D.player.type.*;
    import mortal.game.utils.*;
    import mortal.game.view.copy.crossMainCity.*;

    public class StatuePlayer extends Game2DPlayer
    {
        protected var _info:CrossMainCityStatueInfo;
        protected var _bodyPlayer:ActionPlayer;
        protected var _hairPlayer:ActionPlayer;
        protected var _clothHangEffect:EffectPlayer;
        private var _headContainner:HeadContainer;

        public function StatuePlayer()
        {
            return;
        }// end function

        public function updateStatue(param1:CrossMainCityStatueInfo) : void
        {
            var _loc_4:String = null;
            var _loc_5:String = null;
            var _loc_6:String = null;
            var _loc_7:String = null;
            var _loc_8:String = null;
            var _loc_9:String = null;
            var _loc_10:TPlayerModel = null;
            var _loc_11:TPlayerModel = null;
            this._info = param1;
            this.initPlayer();
            this.initHeadContainner();
            this.x2d = param1.x;
            this.y2d = param1.y;
            if (param1.mainCityStatus)
            {
                this._headContainner.updateName(NameUtil.getProxyName(param1.mainCityStatus.entityId) + NameUtil.Spacer + param1.mainCityStatus.name);
            }
            else
            {
                this._headContainner.updateName(Language.getString(11835));
            }
            this._headContainner.updateTitle(200204);
            this.updateHoverArea();
            var _loc_2:* = ECareer._ECareerWarrior;
            var _loc_3:* = ESex._ESexMan;
            var _loc_12:* = MainCityCache.getPostionClothIdByType(EMainCityPosition._EMainCityKing);
            if (param1.mainCityStatus)
            {
                _loc_11 = PlayerModelConfig.instance.getModelInfo(ModelType.CLOTHES, _loc_12, param1.mainCityStatus.sex, param1.mainCityStatus.career);
                _loc_10 = PlayerModelConfig.instance.getModelInfo(ModelType.HAIR, 0, param1.mainCityStatus.sex, param1.mainCityStatus.career);
            }
            else
            {
                _loc_11 = PlayerModelConfig.instance.getModelInfo(ModelType.CLOTHES, _loc_12, ESex._ESexMan, ECareer._ECareerWarrior);
                _loc_10 = PlayerModelConfig.instance.getModelInfo(ModelType.HAIR, 0, ESex._ESexMan, ECareer._ECareerWarrior);
            }
            if (!_loc_11)
            {
                return;
            }
            _loc_4 = _loc_11.mesh + ".md5mesh";
            _loc_5 = _loc_11.bone + ".skeleton";
            _loc_6 = _loc_11.texture;
            _loc_7 = _loc_10.mesh + ".md5mesh";
            _loc_8 = _loc_10.bone + ".skeleton";
            _loc_9 = _loc_10.texture;
            this._bodyPlayer.load(_loc_4, _loc_5, _loc_6);
            this._hairPlayer.load(_loc_7, _loc_8, _loc_9);
            this._bodyPlayer.hang(this._hairPlayer);
            if (_loc_11.selfEffect)
            {
                this._clothHangEffect = EffectPlayerPool.instance.getEffectPlayer(_loc_11.selfEffect, this._bodyPlayer, null, true);
                if (this._clothHangEffect.temple is TempleRole)
                {
                    (this._clothHangEffect.temple as TempleRole).setRoleParams(this._bodyPlayer, null, null);
                }
                this._clothHangEffect.play(PlayMode.ANIMATION_LOOP_MODE);
            }
            else if (this._clothHangEffect)
            {
                this._clothHangEffect.dispose();
                this._clothHangEffect = null;
            }
            return;
        }// end function

        protected function updateHoverArea() : void
        {
            hoverLeft = 30;
            hoverTop = 100;
            hoverWidth = 60;
            hoverHeight = 105;
            return;
        }// end function

        override public function hoverTest(param1:Number, param2:Number, param3:Number, param4:Number) : Boolean
        {
            var _loc_5:* = hoverLeft;
            var _loc_6:* = hoverTop;
            var _loc_7:* = hoverWidth;
            var _loc_8:* = hoverHeight;
            if (this._bodyPlayer)
            {
                _loc_7 = _loc_7 * this._bodyPlayer.scaleX;
                _loc_8 = _loc_8 * this._bodyPlayer.scaleY;
                _loc_5 = _loc_5 * this._bodyPlayer.scaleX;
                _loc_6 = _loc_6 * this._bodyPlayer.scaleY;
            }
            _displayRec.x = this.x2d - param1 - _loc_5;
            _displayRec.y = this.y2d - param2 - _loc_6;
            _displayRec.width = _loc_7;
            _displayRec.height = _loc_8;
            return _displayRec.contains(param3, param4);
        }// end function

        protected function initPlayer() : void
        {
            if (!this._bodyPlayer)
            {
                this._bodyPlayer = FrObjectPool.getObject(ActionPlayer, this);
                this.setActionName(ActionName.Stand);
                this._bodyPlayer.selectEnabled = true;
                this._bodyPlayer.timerContorler = this.timerContorler;
                this._bodyPlayer.scaleX = 5;
                this._bodyPlayer.scaleY = 5;
                this._bodyPlayer.scaleZ = 5;
                FrEventDispatcher.instance.proxyAddEventListener(this._bodyPlayer, Engine3dEventName.InitComplete, this.onInitBodyPlayer);
                this._bodyPlayer.play();
            }
            if (!this._hairPlayer)
            {
                this._hairPlayer = FrObjectPool.getObject(ActionPlayer, this);
                this._hairPlayer.changeAction(ActionName.Stand);
                this._hairPlayer.hangBoneName = BoneConst.ModelHangHairBone;
                this._hairPlayer.selectEnabled = false;
                this._hairPlayer.enabeldDrawDefault = false;
                this._hairPlayer.timerContorler = this.timerContorler;
                this._hairPlayer.play();
            }
            this.timerContorler.active();
            this.addChild(this._bodyPlayer);
            return;
        }// end function

        public function setActionName(param1:String) : void
        {
            this._bodyPlayer.changeAction(param1);
            this.updateNamePosition();
            return;
        }// end function

        protected function updateNamePosition() : void
        {
            if (this._headContainner)
            {
                this._headContainner.y = this._bodyPlayer.getBoneGlobleY(this._headContainner.hangBoneName) - 10;
            }
            return;
        }// end function

        protected function initHeadContainner() : void
        {
            if (!this._headContainner)
            {
                this._headContainner = FrObjectPool.getObject(HeadContainer, this);
                this.addChild(this._headContainner);
            }
            return;
        }// end function

        protected function onInitBodyPlayer(event:Event) : void
        {
            if (this._bodyPlayer)
            {
                this.updateNamePosition();
            }
            return;
        }// end function

        override public function dispose(param1:Boolean = true) : void
        {
            if (this._clothHangEffect)
            {
                this._clothHangEffect.dispose();
                this._clothHangEffect = null;
            }
            if (this._hairPlayer)
            {
                this._bodyPlayer.unHang(this._hairPlayer);
                this._hairPlayer.dispose();
                this._hairPlayer = null;
            }
            if (this._bodyPlayer)
            {
                this._bodyPlayer.dispose();
                this._bodyPlayer = null;
            }
            if (this._headContainner)
            {
                this._headContainner.dispose();
                this._headContainner = null;
            }
            this._info = null;
            return;
        }// end function

    }
}
